package com.snail.common;

import com.snail.common.entity.Page;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ResultUtil implements Serializable {

    public ResultUtil() {
    }

    /**
     * 成功的无参的返回封装
     */
    public static Map<String, Object> result() {
        return result(ResultCodeEnum.RESULT_SUCCESS);
    }

    /**
     * 成功的返回封装 data、jwtToken
     *
     * @param data 数据
     */
    public static Map<String, Object> result(Object data) {
        Map<String, Object> map = new HashMap();
        map.put("code", ResultCodeEnum.RESULT_SUCCESS.getCode());
        map.put("message", ResultCodeEnum.RESULT_SUCCESS.getMessage());
        map.put("data", data);
        return map;
    }

    /**
     * 成功的返回封装 data、jwtToken
     * @param page 分页page
     */
    public static Map<String, Object> result(Page page) {
        Map<String, Object> map = new HashMap();
        map.put("code", ResultCodeEnum.RESULT_SUCCESS.getCode());
        map.put("message", ResultCodeEnum.RESULT_SUCCESS.getMessage());
        map.put("data", page.getData());
        page.setData(null);
        map.put("page", page);
        return map;
    }

    /**
     * @param status  状态
     * @param message 消息
     * @param data    数据
     */
    public static Map<String, Object> result(int status, String message, Object data) {
        Map<String, Object> map = new HashMap();
        map.put("code", status);
        map.put("message", message);
        map.put("data", data);
        return map;
    }

    /**
     * @param respCode 结果枚举
     */
    public static Map<String, Object> result(ResultCodeEnum respCode) {
        Map<String, Object> map = new HashMap();
        map.put("code", respCode.getCode());
        map.put("message", respCode.getMessage());
        return map;
    }

    /**
     * @param respCode 结果枚举
     * @param data     数据
     */
    public static Map<String, Object> result(Map data, ResultCodeEnum respCode) {
        Map<String, Object> map = new HashMap();
        map.put("code", respCode.getCode());
        map.put("message", respCode.getMessage());
        map.put("data", data);
        return map;
    }
}
